import React from 'react'
import TYHpublic from './TYHpublic'
import { Tabs, Spin } from 'antd';
import pubTable from './publicTable'
import { inject, observer } from 'mobx-react'
import './wzCss/taoyouhui.css'
const { Pubtable } = pubTable
const { TabPane } = Tabs;
@inject('wz')
@observer
class TYH extends React.Component {
    constructor() {
        super()
        this.state = {
            key: '1',
            flag: false, //转圈圈加载中
        }
    }
    tabsCallback = async (key, obj) => {
        await this.setState({
            flag: true
        })
        await this.dealNumsDone()
        if (key === '1') {
            this.props.wz.key = key
            await this.props.wz.getYHData(obj)
            await this.setState({
                key: key,
                flag: false
            });
        } else if (key === '2') {
            this.props.wz.key = key
            await this.props.wz.getQGData(obj)
            await this.setState({
                key: key,
                flag: false
            });
        } else if (key === '3') {
            this.props.wz.key = key
            await this.props.wz.getBTData(obj)
            await this.setState({
                key: key,
                flag: false
            });
        }
    }
    async componentDidMount() {
        await this.props.wz.getYHData()
    }

    // 父组件触发子组件的事件
    dealNumsDone = (obj) => {   //批量处理相关  执行子组件批量处理函数
        this.$child.clearSelect();
    }
    childEvevnt = (event) => {  //批量处理相关
        // console.log(event);
        this.$child = event 
    }


    kidReset = () => {
        this.tabsCallback(this.state.key)
    }

    kidSelect = async (obj) => {    //selection
        let newObj = {
            type: 'activeState',
            value: obj
        }
        await this.tabsCallback(this.state.key, newObj)
        await this.setState({
            flag: false
        });
    }
    //搜索btn
    kidSearchBtn = async (obj) => {
        let newObj = {
            type: 'activeContent',
            value: obj
        }
        await this.tabsCallback(this.state.key, newObj)
        await this.setState({
            flag: false
        });
    }
    //发起审核请求
    render() {
        return (
            <div>
                <div className='box'>
                    <Spin size='large' spinning={this.state.flag} />
                </div>
                <Tabs animated={false} defaultActiveKey={this.state.key} onChange={this.tabsCallback}>
                    <TabPane tab="团购优惠" key="1">
                        <TYHpublic type='团购优惠' searchBtn={this.kidSearchBtn} zzreset={this.kidReset} select={this.kidSelect} numsDone={this.dealNumsDone} />
                        <Pubtable childEvevnt={this.childEvevnt} data={this.props.wz.data} coldata={this.props.wz.columns} />
                    </TabPane>
                    <TabPane tab="限时抢购" key="2">
                        <TYHpublic type='限时抢购' searchBtn={this.kidSearchBtn} zzreset={this.kidReset} select={this.kidSelect} numsDone={this.dealNumsDone} />
                        <Pubtable childEvevnt={this.childEvevnt} data={this.props.wz.data} coldata={this.props.wz.columns} />
                    </TabPane>
                    <TabPane tab="购房补贴" key="3">
                        <TYHpublic type='购房补贴' searchBtn={this.kidSearchBtn} zzreset={this.kidReset} select={this.kidSelect} numsDone={this.dealNumsDone} />
                        <Pubtable childEvevnt={this.childEvevnt} data={this.props.wz.data} coldata={this.props.wz.columns} />
                    </TabPane>
                </Tabs>
            </div>
        )
    }
}
export default TYH
